﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CVSA.Suporte.Sinacor.BMFBovespa.ConsultaRemedy
{
    public partial class Cesta : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            dtgCesta.DataSource = new Negocio.Remedy().getCesta();
            dtgCesta.DataBind();
        }

        int qtdDes, qtdAnd, qtdPend, qtdTotal, qtdFec = 0;
        protected void dtgCesta_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dr = (e.Row.DataItem as DataRowView);
                Label lblTotal = (e.Row.FindControl("lblTotalPessoa") as Label);
                int qtdTotalPessoa = (int.Parse(dr["QTD_DES"].ToString()) + int.Parse(dr["QTD_AND"].ToString()) + int.Parse(dr["QTD_PEND"].ToString()));
                qtdDes += int.Parse(dr["QTD_DES"].ToString());
                qtdAnd += int.Parse(dr["QTD_AND"].ToString());
                qtdPend += int.Parse(dr["QTD_PEND"].ToString());
                qtdFec += int.Parse(dr["QTD_FEC"].ToString());
                qtdTotal += qtdTotalPessoa;
                lblTotal.Text = qtdTotalPessoa.ToString();

                int nCor = int.Parse(dr["QTD_DES"].ToString()) + int.Parse(dr["QTD_AND"].ToString());
                e.Row.Style.Clear();
                if (nCor < 3)
                {
                    e.Row.Style.Add("background-color", "#C6EFCE");
                    e.Row.Style.Add("color", "#006100");
                }
                else if (nCor == 3)
                {
                    e.Row.Style.Add("background-color", "#FFEB9C");
                    e.Row.Style.Add("color", "#9C6500");
                }
                else
                {
                    e.Row.Style.Add("background-color", "#FFC7CE");
                    e.Row.Style.Add("color", "#9C0006");
                }
                
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                (e.Row.FindControl("lblQtdDes") as Label).Text = qtdDes.ToString();
                (e.Row.FindControl("lblQtdAnd") as Label).Text = qtdAnd.ToString();
                (e.Row.FindControl("lblQtdPend") as Label).Text = qtdPend.ToString();
                (e.Row.FindControl("lblQtdTotal") as Label).Text = qtdTotal.ToString();
                (e.Row.FindControl("lblQtdFec") as Label).Text = qtdFec.ToString();
            }

        }
    }
}
